home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-13
/
me_cd22.zip
/
MC2MUTT.ZIP
/
FACT.MUT
< prev
next >
Wrap
Text File
|
1992-04-27
|
410b
|
19 lines
; Factorial the recursive way
(const NUMBER 0x03)
(defun
fact ;; the recursive part. input: x output: x!
{
(if (== (arg 0) 0) 1 ; 0! = 1
(* (arg 0) (fact (- (arg 0) 1))) ; x! = x * (x-1)!
)
}
! ;; the main routine
{
(int x)
(x (convert-to NUMBER (ask "Take factorial of: ")))
(msg x "! = " (fact x))
}
MAIN { (!) } ;; (! 5) produces "5! = 120"
)